/*
    Bandleader
    Copyright (c) 2006 by Grant Yoshida

    Licensed under the GPL version 2 or later,
    please see COPYING for details.
*/

#include "ChangeChord.h"
//
#include "ChordView.h"
#include "Document.h"

ChangeChord::ChangeChord(ChordView *view, int index, const QString &text) :
    QUndoCommand("Change Chord"),
    m_view(view),
    m_document(),
    m_index(index),
    m_text(text),
    m_oldText()
{
    if (m_view)
        m_document = m_view->getDocument();

    if (m_document)
        m_oldText = m_document->chordAt(m_index);
}

void ChangeChord::undo()
{
    if (m_document)
        m_document->setChord(m_index, m_oldText);

    if (m_view)
        m_view->setCursorPosition(m_index);
}

void ChangeChord::redo()
{
    if (m_document)
        m_document->setChord(m_index, m_text);

    if (m_view)
        m_view->setCursorPosition(m_index);
}
